#!/usr/bin/python
# -*- coding: UTF-8 -*-
import configparser
import os
import sys

config_file_name = 'config.ini'


# 打包成exe必须要对文件路径做判断，否则会读取不到配置文件
def get_path():
    exe_running_path = os.path.dirname(sys.executable)  # 获取exe所在路径
    exe_path = os.path.dirname(sys.path[0])  # 获取的是exe所在路径的上级路径
    print('exe_path=' + exe_path + ', exe_running_path=' + exe_running_path)
    if os.path.exists(os.path.join(exe_path, config_file_name)):
        return os.path.join(exe_path, config_file_name)
    else:
        return os.path.join(exe_running_path, config_file_name)


def get_conf():
    file_path = get_path()
    print('file_path=' + file_path)
    config = configparser.ConfigParser()
    config.read(file_path)
    return config


def get_j_u_dev():
    return get_conf().get('jenkins_dev', 'jenkins_url')


def get_j_n_dev():
    return get_conf().get('jenkins_dev', 'jenkins_name')


def get_j_p_dev():  # throw configparser.NoSectionError
    return get_conf().get('jenkins_dev', 'jenkins_pass')


def get_j_u_rc():
    return get_conf().get('jenkins_rc', 'jenkins_url')


def get_j_n_rc():
    return get_conf().get('jenkins_rc', 'jenkins_name')


def get_j_p_rc():
    return get_conf().get('jenkins_rc', 'jenkins_pass')


def get_j_u_prd():
    return get_conf().get('jenkins_prd', 'jenkins_url')


def get_j_n_prd():
    return get_conf().get('jenkins_prd', 'jenkins_name')


def get_j_p_prd():
    return get_conf().get('jenkins_prd', 'jenkins_pass')


def get_g_url():
    return get_conf().get('git_lab', 'gitlab_url')


def get_g_name():
    return get_conf().get('git_lab', 'gitlab_name')


def get_g_pass():
    return get_conf().get('git_lab', 'gitlab_pass')


def get_tag_rc():
    return get_conf().get('tag', 'prefix_rc')


def get_tag_prd():
    return get_conf().get('tag', 'prefix_prd')

